package com.ddwl.message.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.message.service.ShopMessageNoticeService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.gate.ShopMessageInfoBo;
import com.ddwl.schema.bo.gate.ShopMessageInfoCreateBo;
import com.ddwl.schema.bo.gate.ShopMessageUserBo;
import com.ddwl.schema.bo.message.ShopMessageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.gate.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 站内信消息服务
 * @author Admin
 */
@RestController
@RequestMapping("/shopMessageNotice")
@Api(tags = "门店站内信消息服务")
public class ShopMessageNoticeController extends BaseController {

    @Resource
    public ShopMessageNoticeService shopMessageNoticeService;

    @PostMapping("/ConfList")
    @ApiOperation("获取消息配置列表")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<ShopMessageInfoVo>> getConfList(@RequestBody PageBo<ShopMessageInfoBo> pageBo){
        return RestVo.ok(shopMessageNoticeService.getList(pageBo));
    }

    @PostMapping("/create")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("创建消息模板")
    public RestVo createMessage(@Valid @RequestBody ShopMessageInfoCreateBo pageBo){
        shopMessageNoticeService.createMessage(pageBo);
        return RestVo.ok();
    }


    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @GetMapping("/detail")
    @ApiOperation("查看详情 多典后台")
    public RestVo<ShopMessageInfoVo> detail(@RequestParam(name = "id") String id){
        return RestVo.ok(shopMessageNoticeService.detail(id));
    }

    @DeleteMapping("del/{messageInfoId}")
    @ApiOperation("删除消息模板")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo delete(@PathVariable("messageInfoId")String messageInfoId){
        shopMessageNoticeService.delete(messageInfoId);
        return RestVo.ok();
    }

    @PostMapping("/getMessage")
    @ApiOperation("查看当前用户消息列表")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<PageVo<ShopMessageUserListVo>> getMessageList(@RequestBody PageBo<ShopMessageUserBo> pageBo){
        pageBo.getParam().setShopId(getShopId());
       return RestVo.ok(shopMessageNoticeService.messageList(pageBo));
    }

    @PostMapping("/getMessageDetail")
    @ApiOperation("查看当前用户消息详情")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<ShopMessageInfoDetailVo> getMessageDetail(@RequestBody ShopMessageUserBo messageUserBo){
        messageUserBo.setShopId(getShopId());
        return RestVo.ok(shopMessageNoticeService.getMessageDetail(messageUserBo));
    }

    @PostMapping("/getDataList")
    @ApiOperation("查看数据列表")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    public RestVo<PageVo<ShopMessageDataVo>> getDataList(@RequestBody PageBo<ShopMessageUserBo> pageBo){
        return RestVo.ok(shopMessageNoticeService.getDataList(pageBo));
    }

    @GetMapping("getHasReaded/{shopId}")
    @ApiOperation("判断用户是否有无未读消息")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<ShopMessageIsReadVo> getHasReaded(@PathVariable String shopId){
        return RestVo.ok(shopMessageNoticeService.hasUnRead(shopId));
    }

    /**
     * 给指定店铺推送消息
     * @param bo
     * @return
     */
    @PostMapping("/pushMessageToShop")
    @ApiOperation("给指定店铺推送消息")
    @Auth(product = {BaseEnum.ProductEnum.API})
    RestVo pushMessageToShop(@RequestBody ShopMessageBo bo){
        shopMessageNoticeService.pushMessageToShop(bo);
        return RestVo.ok();
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        shopMessageNoticeService.changeId();
        return RestVo.ok();
    }

}